package com.itcodai.config.thread;

import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

//@Component
//@Endpoint(id = "threadpool")
public class ThreadPoolEndpoint {

    private final ThreadPoolTaskExecutor taskExecutor;

    public ThreadPoolEndpoint(ThreadPoolTaskExecutor taskExecutor) {
        this.taskExecutor = taskExecutor;
    }

    @ReadOperation
    public ThreadPoolStatus threadPoolStatus() {
        return new ThreadPoolStatus(
                taskExecutor.getCorePoolSize(),
                taskExecutor.getMaxPoolSize(),
                taskExecutor.getPoolSize(),
                taskExecutor.getActiveCount()
        );
    }

    public static class ThreadPoolStatus {
        private final int corePoolSize;
        private final int maxPoolSize;
        private final int currentPoolSize;
        private final int activeThreads;

        public ThreadPoolStatus(int corePoolSize, int maxPoolSize, int currentPoolSize, int activeThreads) {
            this.corePoolSize = corePoolSize;
            this.maxPoolSize = maxPoolSize;
            this.currentPoolSize = currentPoolSize;
            this.activeThreads = activeThreads;
        }

        // Getters for the fields
    }
}
